<?php

/**
 * This is the model class for table "ld_deposit_history".
 *
 * The followings are the available columns in table 'ld_deposit_history':
 * @property integer $serialno
 * @property integer $user_id
 * @property string $deposit_date
 * @property double $lr_amount
 * @property string $lr_currency
 */
class DepositHistory extends BaseActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return DepositHistory the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'ld_deposit_history';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('user_id', 'numerical', 'integerOnly'=>true),
			array('lr_amount', 'numerical'),
			array('lr_currency', 'length', 'max'=>20),
			array('deposit_date', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('serialno, user_id, deposit_date, lr_amount, lr_currency', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'serialno' => 'Serialno',
			'user_id' => 'User',
			'deposit_date' => 'Deposit Date',
			'lr_amount' => 'Lr Amount',
			'lr_currency' => 'Lr Currency',
		);
	}
        
        public  static function getDepositHistoryByUserId($user_id)
        {
            $query = "SELECT DATE_FORMAT(deposit_date, '%H:%i:%s %d-%m-%Y') as deposit_date, lr_amount, lr_currency
                        FROM ld_deposit_history
                        WHERE user_id = $user_id
                        ORDER BY deposit_date DESC";
            return DepositHistory::model()->findAllBySql($query);
        }
}